#ifndef __losor_object_h__
#define __losor_object_h__

#include <inttype.h>

struct object;
struct cluster;
struct rule;
struct story;
struct relation;
struct language;

enum otype
{
    TOBJECT,
    TCLUSTER,
    TRULE,
    TSTORY,
    TRELATION,
    TLANGUAGE,
};

enum rtype
{
    TCREATE,
    TMODIFY,
    TDELETE,
    TCHECK,
};

struct object
{
    uint64 id;
    uint32 ref;
    uint32 nvisit;
    otype type;
    cluster *used;
};

struct cluster : public object
{
    uint32 nobj;
    object **obj;
};

struct rule : public object
{
    cluster *factor;
    cluster *result;
};

struct story : public object 
{
    object *when;
    object *where;
    object *who;
    object *action;
    object *what;
};

struct relation : public object
{
    object *relate;
    cluster *obj;
};

struct language : public object
{
    char* letter;
};

object* story_proc( story* obj )
{

    return NULL;
}

object* relation_proc( relation* obj )
{
    
    return NULL;
}

object* rule_proc( rule* obj )
{
    
    return NULL;
}

object* language_proc( language* obj )
{
    return NULL;
}

object* cluster_proc( cluster* obj )
{
    /*
     * to find another type of object  who matches the cluster's member
     * (cluster can be an object when there is a rule about it)
     */
    object* otmp,ctmp;
    int i;
    for( i = 0; i < obj->nobj; ++i )
    {
        otmp = find_object( obj->obj[i] );
        ctmp = match_object( otmp, obj );
    }
    return NULL;
}

object* object_proc( object* obj )
{
    
    return NULL;
}

object* process( object* obj )
{
    switch( obj->get_type() )
    {
    case TOBJECT:
        return object_proc( obj );
    case TCLUSTER:
        return cluster_proc( (cluster*)obj );
    case TRULE:
        return rule_proc( (rule*)obj );
    case TSTORY:
        return story_proc( (story*)obj );
    case TRELATION:
        return relation_proc( (relation*)obj );
    default:
        break;
    }
    return NULL;
}

/*
object* myself = 
{
    succeeded to create objects( with failure )
    {
        object,
        cluster,
        rule,
        story,
        relation,
    },
    succeeded to verify objects( with verifying false )
    {
        object,
        cluster,
        rule,
        story,
        relation,
    },
    hunger ( more or less )
    {
        month
        {
            object,
            cluster,
            rule,
            story,
            relation,
        },
        day
        {
            object,
            cluster,
            rule,
            story,
            relation,
        },
        minute
        {
            object,
            cluster,
            rule,
            story,
            relation,
        },
    },
    breed
    {
        object,
        cluster,
        rule,
        story,
        relation,
    },
}
*/

#endif // __losor_object_h__
